package com.atguigu.gmall;

import com.atguigu.gmall.common.constant.RedisConst;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * @author: atguigu
 * @create: 2023-07-22 11:50
 */
@Slf4j
@SpringBootApplication
//当需要扫描指定包，在注解中通过scanBasePackages指定扫描包
//@SpringBootApplication(scanBasePackages = {"com.atguigu.gmall", "cn.atguigu"})
@EnableAsync //开启Springboot默认自带异步功能（默认产生线程池）
public class ProductApp implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(ProductApp.class, args);
    }

    @Autowired
    private RedissonClient redissonClient;

    /**
     * 初始化布隆过滤器：要求IOC容器中RedissonClient对象已经创建
     * springboot项目启动成功后,执行一次该方法
     *
     * @param args incoming main method arguments
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        log.info("[商品服务]初始化布隆过滤器 start");
        //1.调用Redisson客户端对象创建布隆过滤器
        RBloomFilter<Object> bloomFilter = redissonClient.getBloomFilter(RedisConst.SKU_BLOOM_FILTER);
        //2.指定布隆过滤器数据规模以及误判率
        bloomFilter.tryInit(100000, 0.03);
        log.info("[商品服务]初始化布隆过滤器 end");
    }


}
